<template>
  <div>
    <el-form
      inline
    >
      <el-form-item label="负载功率">
        <el-select v-model="loadpower" @change="selectChange">
          <el-option
            v-for="(item ,index) in loadpowerArr"
            :key="index"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="负载每天工作时">
        <el-select v-model="loadtime" @change="selectChange">
          <el-option
            v-for="item in loadtimeArr"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <el-form
      inline
    >
      <el-form-item label="所在地区">
        <el-select v-model="zone" @change="zoneChange">
          <el-option
            v-for="(item,index) in comArr"
            :key="index"
            :label="item.zone"
            :value="index"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="平均日照时间(小时)">
        <el-input v-model="zTime" @change="zTimeChange" />
      </el-form-item>
      <el-form-item label="纬度">
        <el-input v-model="zLatitude" disabled />
      </el-form-item>
      <el-form-item label="最佳安装角度">
        <el-input v-model="zAngle" disabled />
      </el-form-item>
    </el-form>

    <el-form
      inline
    >
      <el-form-item label="蓄电池电压">
        <el-select v-model="vSelect" @change="selectChange">
          <el-option
            v-for="item in vArr"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="负载要求持续阴雨天数">
        <el-select v-model="rainyday" @change="selectChange">
          <el-option
            v-for="item in rainydayArr"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="阴雨天间隔天数">
        <el-select v-model="rainydays" @change="selectChange">
          <el-option
            v-for="item in rainydaysArr"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="放电深度">
        <el-select v-model="depth" @change="selectChange">
          <el-option
            v-for="item in depthArr"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <el-form
      inline
    >
      <el-form-item label="电池板功率">
        <el-input v-model="txtPower" @change="txtPowerChange" />
      </el-form-item>
      <el-form-item label="每天消耗的电量(度)">
        <el-input v-model="txtConsume" disabled />

      </el-form-item>
      <el-form-item label="每天消耗的电量(AH)">
        <el-input v-model="txtAH" disabled />
      </el-form-item>
    </el-form>
    <el-form
      inline
    >
      <el-form-item label="蓄电池容量(AH)">
        <el-input v-model="txtCapacity" @change="txtCapacityChange" />

      </el-form-item>
      <el-form-item label="蓄电池充满天">
        <el-input v-model="txtDay" disabled />
      </el-form-item>
      <el-form-item label="可持续工作(天)">
        <el-input v-model="txtWork" disabled />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Calculation',
  data() {
    return {
      vSelect: null,
      rainyday: null,
      rainydays: null,
      depth: null,
      loadpower: null,
      loadtime: null,
      zone: 0,
      zTime: '3.42',
      zLatitude: '30.23',
      zAngle: '33.23',
      txtPower: '29.24',
      txtConsume: '0.06',
      txtAH: '5.21',
      txtCapacity: '',
      txtDay: '',
      txtWork: '',
      txtCharging: 0.75, // 电池充电效率75%

      loadpowerArr: ['10', '20', '30', '40', '50', '60', '70', '80', '90', '100', '110', '120', '130', '140', '150', '160', '170', '180', '190', '200'],
      loadtimeArr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'],
      comArr: [
        {
          'zone': '杭州',
          'values':
              {
                'time': '3.42',
                'latitude': '30.23',
                'angle': '33.23'
              }
        },
        {
          'zone': '长春',
          'values':
              {
                'time': '4.8',
                'latitude': '43.9',
                'angle': '44.9'
              }
        },
        {
          'zone': '南昌',
          'values':
              {
                'time': '3.81',
                'latitude': '28.67',
                'angle': '30.67'
              }
        },
        {
          'zone': '沈阳',
          'values':
              {
                'time': '4.6',
                'latitude': '41.77',
                'angle': '42.77'
              }
        },
        {
          'zone': '福州',
          'values':
              {
                'time': '3.46',
                'latitude': '26.08',
                'angle': '30.08'
              }
        },
        {
          'zone': '北京',
          'values':
              {
                'time': '5',
                'latitude': '39.8',
                'angle': '43.8'
              }
        },
        {
          'zone': '济南',
          'values':
              {
                'time': '4.44',
                'latitude': '36.68',
                'angle': '42.68'
              }
        },
        {
          'zone': '天津',
          'values':
              {
                'time': '4.65',
                'latitude': '39.1',
                'angle': '44.1'
              }
        },
        {
          'zone': '郑州',
          'values':
              {
                'time': '4.04',
                'latitude': '34.72',
                'angle': '41.72'
              }
        },
        {
          'zone': '武汉',
          'values':
              {
                'time': '3.8',
                'latitude': '30.63',
                'angle': '37.63'
              }
        },
        {
          'zone': '太原',
          'values':
              {
                'time': '4.8',
                'latitude': '37.78',
                'angle': '42.78'
              }
        },
        {
          'zone': '长沙',
          'values':
              {
                'time': '3.22',
                'latitude': '28.2',
                'angle': '34.2'
              }
        },
        {
          'zone': '广州',
          'values':
              {
                'time': '3.52',
                'latitude': '23.13',
                'angle': '16.13'
              }
        },
        {
          'zone': '西宁',
          'values':
              {
                'time': '5.5',
                'latitude': '36.75',
                'angle': '37.75'
              }
        },
        {
          'zone': '海口',
          'values':
              {
                'time': '3.75',
                'latitude': '20.03',
                'angle': '32.03'
              }
        },
        {
          'zone': '兰州',
          'values':
              {
                'time': '4.4',
                'latitude': '36.05',
                'angle': '44.05'
              }
        },
        {
          'zone': '南宁',
          'values':
              {
                'time': '3.54',
                'latitude': '22.82',
                'angle': '27.82'
              }
        },
        {
          'zone': '银川',
          'values':
              {
                'time': '5.5',
                'latitude': '38.48',
                'angle': '40.48'
              }
        },
        {
          'zone': '成都',
          'values':
              {
                'time': '2.87',
                'latitude': '30.67',
                'angle': '32.67'
              }
        },
        {
          'zone': '西安',
          'values':
              {
                'time': '3.6',
                'latitude': '34.4',
                'angle': '48.4'
              }
        },
        {
          'zone': '贵阳',
          'values':
              {
                'time': '2.84',
                'latitude': '26.58',
                'angle': '34.58'
              }
        },
        {
          'zone': '上海',
          'values':
              {
                'time': '3.8',
                'latitude': '31.17',
                'angle': '34.17'
              }
        },
        {
          'zone': '昆明',
          'values':
              {
                'time': '4.26',
                'latitude': '25.02',
                'angle': '17.02'
              }
        },
        {
          'zone': '南京',
          'values':
              {
                'time': '3.94',
                'latitude': '32',
                'angle': '37'
              }
        },
        {
          'zone': '拉萨',
          'values':
              {
                'time': '6.7',
                'latitude': '29.7',
                'angle': '21.7'
              }
        },
        {
          'zone': '合肥',
          'values':
              {
                'time': '3.69',
                'latitude': '31.85',
                'angle': '40.85'
              }
        },
        {
          'zone': '哈尔滨',
          'values':
              {
                'time': '4.4',
                'latitude': '45.68',
                'angle': '48.68'
              }
        },
        {
          'zone': '呼和浩特',
          'values':
              {
                'time': '5.6',
                'latitude': '40.78',
                'angle': '48.68'
              }
        },
        {
          'zone': '乌鲁木齐',
          'values':
              {
                'time': '4.6',
                'latitude': '43.78',
                'angle': '55.78'
              }
        }
      ],
      vArr: ['2', '6', '12', '24', '36', '48'],
      rainydayArr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'],
      rainydaysArr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'],
      depthArr: ['5', '10', '20', '30', '40', '50', '60', '70', '80', '90', '100']
    }
  },
  created() {
    this.loadpower = this.loadpowerArr[0],
    this.vSelect = this.vArr[2]
    this.rainyday = this.rainydayArr[1]
    this.rainydays = this.rainydaysArr[19]
    this.depth = this.depthArr[5]
    this.loadtime = this.loadtimeArr[4]
    this.selectChange()
  },
  methods: {
    zoneChange() {
      const aLength = this.comArr.length
      // 联动平均日照时间、纬度、最佳安装角度
      for (let j = 0; j < aLength; j++) {
        if (this.zone === j) {
          this.zTime = this.comArr[j].values.time
        }
      }

      this.selectChange()
    },
    selectChange() {
      const aLength = this.comArr.length
      // 联动平均日照时间、纬度、最佳安装角度
      for (let j = 0; j < aLength; j++) {
        if (this.zone === j) {
          this.zLatitude = this.comArr[j].values.latitude
          this.zAngle = this.comArr[j].values.angle
        }
      }

      // 计算每天耗电量（度）（等于负载功率*负载工作时间*0.001/电池放电效率（0.8））
      const txtEffect = 0.8// 电池放电效率80%

      const txtConsume = this.loadpower * this.loadtime * 0.001 / txtEffect// 每天耗电量（度）
      this.txtConsume = parseFloat(txtConsume.toFixed(2))

      // 每天消耗的电量（AH）(等于负载功率*负载工作时间/0.8/蓄电池电压)

      const txtAH = this.loadpower * this.loadtime / 0.8 / this.vSelect// 每天消耗的电量（AH）
      this.txtAH = parseFloat(txtAH.toFixed(2))

      // 计算蓄电池容量（等于每天消耗的电量（AH）*阴雨天数/蓄电池放电深度）
      const txtCapacity = this.txtAH * this.rainyday / (this.depth / 100)// 蓄电池容量
      this.txtCapacity = parseFloat(txtCapacity.toFixed(2))

      // 计算电池板功率（等于(每天消耗的电量（AH）+蓄电池容量/阴雨天间隔天数)*蓄电池电压/电池充电效率（0.75）/平均日照时间）

      const txtPower = (this.txtAH + this.txtCapacity / this.rainydays) * this.vSelect / this.txtCharging / this.zTime// 电池板功率
      this.txtPower = parseFloat(txtPower.toFixed(2))

      const txtWork = this.txtCapacity * 0.8 * this.vSelect * this.depth / this.loadpower / this.loadtime / 100// 可连续工作天数
      this.txtWork = parseFloat(txtWork.toFixed(2))
      const txtDay = this.txtCapacity * this.vSelect * this.depth / this.txtPower / this.zTime / 75// 多少天可被充满
      this.txtDay = parseFloat(txtDay.toFixed(2))
    },
    txtCapacityChange() {
      const txtWork = this.txtCapacity / (this.loadpower * this.loadtime / 0.8 / this.vSelect / (this.depth / 100))// 可连续工作天数
      const txtDay = this.txtCapacity * this.vSelect * this.depth / this.txtPower / this.zTime / 75// 多少天可被充满
      this.txtWork = parseFloat(txtWork.toFixed(2))
      this.txtDay = parseFloat(txtDay.toFixed(2))
    },
    txtPowerChange() {
      const txtDay = this.txtCapacity * this.vSelect * this.depth / this.txtPower / this.zTime / 75// 多少天可被充满
      this.txtDay = parseFloat(txtDay.toFixed(2))
    },
    zTimeChange() {
      const txtAH = parseFloat(this.txtAH1)// 每天消耗的电量（AH）
      const txtPower = (txtAH + this.txtCapacity / this.rainydays) * this.vSelect / this.txtCharging / this.zTime// 电池板功率
      this.txtPower = parseFloat(txtPower.toFixed(2))
    }
  }
}
</script>


